from rest_framework import serializers
from .models import Enterprise, Recruit, City
from user.models import User


# 企业信息系简单列化器
class EnterpriseSimpleModelserializer(serializers.ModelSerializer):
    class Meta:
        model = Enterprise
        fields = [
            'id',
            'name',
            'labels',
            'logo',
            # 注意,这是主表Recruit设置在从表关联字段的related_name字段
            'recruits',
            'summary'
        ]


# 招聘信息列表序列化器
class RecommendModelSerializer(serializers.ModelSerializer):
    enterprise = EnterpriseSimpleModelserializer()

    class Meta:
        model = Recruit
        fields = [
            'id',
            'jobname',
            'salary',
            'condition',
            'education',
            'type',
            'city',
            'createtime',
            'enterprise',
            'labels'
        ]


# 企业信息系全列化器
class EnterpriseAllModelserializer(serializers.ModelSerializer):
    # 注意,1对多需要添加many=True
    recruits = RecommendModelSerializer(many=True)

    class Meta:
        model = Enterprise
        fields = [
            'id',
            'name',
            'labels',
            'logo',
            # 注意,这是主表Recruit设置在从表关联字段的related_name字段
            'recruits',
            'summary',
            'content',
            'city',
            'address',
            'coordinate',
            'url',
            'visits',
            'users'
        ]


# 职位详情
class RecommendDetailModelSerializer(serializers.ModelSerializer):
    enterprise = EnterpriseAllModelserializer()

    class Meta:
        model = Recruit
        fields = '__all__'


# 取消或者收藏职位
class CollectJobsModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Recruit
        fields = ['id']


# 热门城市
class HotCityModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = City
        fields = '__all__'